package com.mcptt.http.auth.process.result.info;

import org.json.JSONException;
import org.json.JSONObject;

import com.cloudptt.api.product.log.Log;
import com.mcptt.http.tool.EncryptionTool;

public class IdTokenResult
{
	private String mcpttId = "sip:1001@crsc.mcx.mnc020.mcc460.5gr";
	private String mcvideoId = "sip:1001@crsc.mcx.mnc020.mcc460.5gr";
	private String mcdataId = "sip:1001@crsc.mcx.mnc020.mcc460.5gr";

	public IdTokenResult(String idToken)
	{
		if(idToken == null
				|| idToken.length() <= 0)
		{
			return;
		}
		try
		{
			String[] strArr = idToken.split("\\.");
			if(strArr == null
					|| strArr.length <= 0
					|| strArr[1] == null
					|| strArr[1].length() <= 0)
			{
				return;
			}
//			for(int i = 0;i < strArr.length;i++)
//			{
//				Log.debug(this.getClass(), "IdTokenResult strArr[" + i + "] = " + strArr[i]);
//				String value = EncryptionTool.decodeBase64(strArr[i]);
//				Log.debug(this.getClass(), "IdTokenResult value = " + value);
//			}
//			Log.debug(this.getClass(), "IdTokenResult strArr = " + strArr);
			String value = EncryptionTool.decodeBase64(strArr[1]);
			Log.debug(this.getClass(), "IdTokenResult value = " + value);
			JSONObject idObj;
			idObj = new JSONObject(value);
			this.mcpttId = idObj.getString("mcptt_id");
			this.mcvideoId = idObj.getString("mcvideo_id");
			this.mcdataId = idObj.getString("mcdata_id");
			Log.debug(this.getClass(), "IdTokenResult mcpttId = " + mcpttId + " mcvideoId = " + mcvideoId + " mcdataId = " + mcdataId);
		} catch (JSONException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public boolean checkReturnParamOk()
	{
		if(mcpttId == null
				|| mcpttId.length() <= 0)
		{
			return false;
		}
		return true;
	}

	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("IdTokenResult  ");
		strBuf.append("mcpttId=").append(mcpttId).append(";");
		strBuf.append("mcvideoId=").append(mcvideoId).append(";");
		strBuf.append("mcdataId=").append(mcdataId).append(";");

		return strBuf.toString();
	}

	public String getMcpttId()
	{
		return mcpttId;
	}
	public String getMcvideoId() {
		return mcvideoId;
	}

	public String getMcdataId() {
		return mcdataId;
	}
}
